{* $Id$ *}
{include_core file="admin/lib/header.html" title="活动列表"}
  <div class="page-header border-bottom clearfix">
    <h2 class="left">活动管理<span>在这里对活动进行管理</span></h2>
    <a href="{AnUrl('event/admin/add')}" class="btn btn-success btn-sm right"><i class="icon-add"></i>发布活动</a>
  </div>
  <div class="search-level1 clearfix">
    <form action="event/admin" method="get">
      <input type="hidden" name="is_advenced" value="0" {if $is_advenced == 1}style="display:none;"{/if}>
      <input type="hidden" name="status" value="{$status}" {if $is_advenced == 1}style="display:none;"{/if}>
      <input type="text" class="left" name="search_filter[title]" value="{$search_filter.title}" placeholder="输入活动标题" {if $is_advenced == 1}style="display:none;"{/if}>
      <button type="submit" class="btn btn-success btn-sm left" {if $is_advenced == 1}style="display:none;"{/if}>搜索</button>
      <a href="javascript:void(0);" class="close js_advanced {if $is_advenced == 1}js_isOpen open{/if}">高级搜索<em></em></a>
    </form>
  </div>
  <div class="search-form js_advancedForm" {if $is_advenced == 0}style="display:none;"{/if}>
    <form action="event/admin" method="get" class="js_focusSearchForm">
      <input type="hidden" name="is_advenced" value="1">
      <input type="hidden" name="status" value="{$status}">
      <p>
        <label for="" class="search-f-label">活动标题：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[title]" value="{$search_filter.title}">
      </p>
      
      <p>
      <label for="" class="search-f-label">发布时间：</label>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[start_date]" value="{$search_filter.start_date}" id="startDate">
        <span class="search-f-line"></span>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[end_date]" value="{$search_filter.end_date}" id="stopDate">
      </p>
      <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button></p>
    </form>
  </div>
  
  <!--start:列表-->
  <table class="list-table">
    <caption>按状态：
      <a href='{AnUrl("event/admin?status=1")}' {if $status == 1} class="label label-primary" {else} class="label label-default" {/if}>正常</a>
      <a href='{AnUrl("event/admin?status=0")}' {if $status == 0} class="label label-primary" {else} class="label label-default" {/if}>已禁用</a>
    </caption>
    <thead><tr>
      {if $status == 1}
      <th style="width:20px;"><input type="checkbox" style="padding:6px;border:1px solid #999;background-color:white;border-radius:2px;" class="selectAll"></th>
      {/if}
      <th>活动ID</th>
      <th style="min-width:100px;">标题</th>
      <th style="width:120px;">推送范围</th>
      <th style="min-width:200px;">活动预览图片</th>
      <th style="width:130px;">发布时间</th>
      <th style="width:60px;">操作</th>
    </tr></thead>
    <tbody>
      {foreach $event_list as $k => $v}
        <tr id="dataList{$v.id}" {if $k%2 == 1} class="bg-gray"{/if} data-id="{$v.id}">
          {if $status == 1}
            <td><input type="checkbox" style="padding:6px;border:1px solid #999;background-color:white;border-radius:2px;" class="js_listSelect" /></td>
          {/if}
          <td>{$v.id}</td>
          <td>{$v.title}</td>
          <td>
            {if $v.push_range == 0}所有人{elseif $v.push_range == 3}经销商和市场人员{elseif $v.push_range == 4}商户端{/if}
          </td>
          <td><img alt="" src="{$v.preview_pic}" width="100"></td>
          <td>{$v.add_time}</td>
          <td>
            <a href="{AnUrl("event/admin/edit?id={$v.id}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>编辑</a>
            {if $v.status == 1}
              <a href="{AnUrl("event/admin/delete?id={$v.id}")}" class="btn btn-danger btn-xs js_deleteOne"><i class="icon-trash icon-white"></i>删除</a>
            {elseif $v.status == 0}
              <a href="{AnUrl("event/admin/change_status?id={$v.id}")}" class="btn btn-success btn-xs js_changeStatus"><i class="icon-trash icon-white"></i>恢复</a>
              <a href="{AnUrl("event/admin/delete_event?id={$v.id}")}" class="btn btn-danger btn-xs js_deleteOneMessage"><i class="icon-trash icon-white"></i>销毁</a>
            {/if}
          </td>
        </tr>
      {foreachelse}
          <tr><td class="txtleft" colspan="6">暂无数据</td></tr>
      {/foreach}
    </tbody>
    {if $status == 1}
    <tfoot><tr><td><input type="checkbox" style="padding:6px;border:1px solid #999;background-color:white;border-radius:2px;" class="selectAll"></td><td colspan="6"><a href="{AnUrl("event/admin/delete")}" class="btn btn-danger btn-xs js_deleteAll">批量删除</a></td></tr></tfoot>
    {/if}
  </table>
  <script type="text/javascript">
  $(function(){
    // 高级搜索
    $('.js_advanced').click(function(e){
      e.preventDefault();
      var thisObj = $(this);
      var outBox  = thisObj.closest('form');
      if (thisObj.hasClass('js_isOpen')) {
        thisObj.removeClass('js_isOpen open');
        outBox.find('input').show();
        outBox.find('button').show();
        $('.js_advancedForm').hide();
      } else {
        thisObj.addClass('js_isOpen open');
        outBox.find('input').hide();
        outBox.find('button').hide();
        $('.js_advancedForm').show();
      }
    });

    // 单个禁用
    $(".js_deleteOne").live('click',function(e){
      e.preventDefault();
      e.stopPropagation();
      var selectId = $(this).closest("tr").attr("id").substring(8);
      var roleId = $(this).closest("tr").data("id");
      if (!selectId) {
        alert('请选择要操作记录');
      }
      
      var clickObj = $(this);
      var url = clickObj.attr("href");
      var cardListBox = clickObj.closest('.cardListBox');
      var lines = $(this).parent().attr('rowspan');
      showConfirm('确定要删除该条活动吗？', 1, function(){
        $.post(url, {  'id':selectId }, function(json){
          if (json.info != 'ok') {
            alert(json.info);
          } else {
            clickObj.closest("tr").fadeOut(function(){
              if (lines) {
                for (var i = 1; i < lines; i++) {
                  $(this).next().remove();
                }
              };
              $(this).remove();
              interLineColor();
              
              if (cardListBox) {
                var trNum = cardListBox.find('.js_deleteOne').length;
                var level_total = cardListBox.attr('data-level_total');
                consoleLog(trNum);
                consoleLog(level_total);
                if (trNum < level_total) {
                  $('.addCard').show();
                }
              }
            });
          }
        }, 'json');
      });
      return false;
    });

    //单个删除
    $(".js_deleteOneMessage").live('click',function(e){
      e.preventDefault();
      e.stopPropagation();
      var selectId = $(this).closest("tr").attr("id").substring(8);
      var roleId = $(this).closest("tr").data("id");
      if (!selectId) {
        alert('请选择要操作记录');
      }
      
      var clickObj = $(this);
      var url = clickObj.attr("href");
      // var cardListBox = clickObj.closest('.cardListBox');
      var lines = $(this).parent().attr('rowspan');
      {literal}
      showConfirm('确定要销毁该条活动吗？', 1, function(){
        $.post(url, {  'id':selectId }, function(json){
          if (json.info != 'ok') {
            alert(json.info);
          } else {
            clickObj.parents("tr").fadeOut(function(){
              if (lines) {
                for (var i = 1; i < lines; i++) {
                  $(this).next().remove();
                }
              };
              $(this).remove();
              interLineColor();
              
              if (cardListBox) {
                var trNum = cardListBox.find('.js_deleteOneMessage').length;
                var level_total = cardListBox.attr('data-level_total');
                consoleLog(trNum);
                consoleLog(level_total);
                if (trNum < level_total) {
                  $('.addCard').show();
                }
              }
            });
            
          }
        }, 'json');
      });
      return false;
    });
    {/literal}
    // 全选
    $("input.selectAll").live('click', function(){
      if ($(this).attr("checked")) {
        $("input.selectAll, input.js_listSelect").not(":disabled").attr("checked", "checked");
        $("input.selectAll, input.js_listSelect").not(":disabled").css("background-color", "#333");
      } else {
        $("input.selectAll, input.js_listSelect").not(":disabled").removeAttr("checked");
        $("input.selectAll, input.js_listSelect").not(":disabled").css("background-color", "#fff");
      }
    });

    // 点击列表选中checkbox
    $("table.list-table tbody tr").click(function(e){
      /*var clickTarget = $(e.target);
      // 当直接点击checkbox时，不做checked的切换
      if (clickTarget.is("input.js_listSelect")) {
        return;
      }*/
      // var listCheckbox = $("input.js_listSelect", $(this));
      var listCheckbox = $(this).find('input.js_listSelect');
      if (listCheckbox.is(":disabled")) {
        return;
      }
      if (listCheckbox.attr("checked")) {
        // listCheckbox.removeAttr("checked");
        listCheckbox.css("background-color",'#333');
      } else {
        // listCheckbox.attr("checked", "checked");
        listCheckbox.css("background-color", "#fff");
      }
    });

    // 批量删除
    $(".js_deleteAll").click(function(e){
      e.preventDefault();
      var url = $(this).attr("href");
      var ids = getCheckedIdList();
      deleteAll(url, ids);
      $("input[name=selectAll]").not(":disabled").removeAttr("checked");
      return false;
    });
    
  });

  /**
   * 获取页面中选中的checkbox对应的ids
   * @requires checkbox上统一加name="js_listSelect"
   * @requires tr的class="dataList1"
   * @return Array 所有选中的id数组
   */
  function getCheckedIdList()
  {
    var ids = [];
    $("input.js_listSelect:checked").not(":disabled").each(function(){
      var selectId = $(this).closest("tr").attr("id").substring(8);
      ids.push(selectId);
    });
    return ids;
  }
  </script>
  {include_core file="admin/lib/pager.html"}
<!--end:列表-->
{load_js file='zclip/jquery.zclip.min.js'}
{load_js file='zclip/ZeroClipboard.js'}
{include_core file="admin/lib/footer.html"}